package com.yl.chainStore.control.warehouse

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.yl.chainStore.common.Constants
import com.yl.chainStore.control.BaseCtrl
import com.yl.chainStore.entity.warehouse.WarehouseGoodSupplier
import com.yl.chainStore.pojo.vo.warehouse.WarehouseGoodSupplierSelectVo
import com.yl.chainStore.services.ICompanyDictionaryService
import com.yl.chainStore.services.warehouse.IWarehouseService
import com.yl.chainStore.services.warehouse.IWarehouseSupplierService
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnSuccess
import com.yl.common.getContext
import com.yl.users.common.annotations.PermsCode
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("warehouse/supplier")
open class WarehouseGoodSupplierController(
	private val iWarehouseSupplierService: IWarehouseSupplierService,
	private val iWarehouseService: IWarehouseService,
	private val iCompanyDictionaryService: ICompanyDictionaryService
) : BaseCtrl() {

	/**
	 * 获取供应商分页
	 */
	@PostMapping("getSupplierPage")
	@PermsCode("warehouse:supplier:getSupplierPage")
	@Transactional
	open fun getSupplierPage(@RequestBody vo: WarehouseGoodSupplierSelectVo): ResponseBody {
		vo.deptId = getContext().subCompanyId
		return returnSuccess(iWarehouseService.supplierPage(Page<WarehouseGoodSupplier>(vo.current, vo.size), vo))
	}

	/**
	 * 详情
	 */
	@GetMapping("getSupplier/{id}")
	@Transactional
	open fun getSupplier(@PathVariable id: Long): ResponseBody {
		return returnSuccess(
			iWarehouseSupplierService.getSupplier(id)
		)
	}

	/**
	 * 创建
	 */
	@PostMapping("createSupplier")
	@PermsCode("warehouse:supplier:createSupplier")
	@Transactional
	open fun createSupplier(@RequestBody supplier: WarehouseGoodSupplier): ResponseBody {
		return iWarehouseService.addSupplier(supplier)
	}

	/**
	 * 修改
	 */
	@PostMapping("updateSupplier")
	@PermsCode("warehouse:supplier:updateSupplier")
	@Transactional
	open fun updateSupplier(@RequestBody supplier: WarehouseGoodSupplier): ResponseBody {
		return iWarehouseSupplierService.updateSupplier(supplier)
	}

	/**
	 * 删除
	 */
	@PostMapping("delSupplier/{id}")
	@PermsCode("warehouse:supplier:delSupplier")
	@Transactional
	open fun delSupplier(@PathVariable id: Long): ResponseBody {
		return iWarehouseSupplierService.delSupplier(id)
	}

	/**
	 * 获取供应商经营类型
	 */
	@GetMapping("getSupplierEnterpriseNature")
	@Transactional
	open fun getSupplierEnterpriseNature(): ResponseBody {
		return returnSuccess(
			iCompanyDictionaryService.getCompanyDetailListToMapIdName(
				Constants.DistId.SUPPLIER_ENTERPRISE_NATURE,
				getContext().companyId,
				getContext().subCompanyId
			)
		)
	}




}
